#include <cassert>
#include <functional>

inline double riemann(std::function<double(double)> f, double a, double b, int nIntervals){
assert(b>=a);
assert(nIntervals > 0);

double dx = (b - a)/(static_cast<double> (nIntervals));
double xi = a;

double result = 0.;

//This for loop iterates over the intervals. In each step the surface of the interval is added.
    for(int i = 1; i<=nIntervals; ++i)
    {
        result += f(xi + dx/2)*dx;
        xi +=dx;
    }
    return result;
}
